/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Catalogue;

import ObjetData.Article;
import java.util.ArrayList;

/**
 *
 * @author julien
 */
public class Panier {

    private ArrayList<Article> articles = new ArrayList<Article>();

    public void add(Article a) {
        this.articles.add(a);
    }

    public void remove(Article a) {
        for (int i = 0; i < articles.size(); i++) {
            Article article = articles.get(i);
            if (article.getIdArticle() == a.getIdArticle()) {
                this.articles.remove(i);
            }
        }
    }

    public ArrayList<Article> getDetailPanier() {
        return this.articles;
    }

    public int getNumberItems() {
        try {
            return this.articles.size();
        } catch (Exception e) {
            return 0;
        }
    }

    @Override
    public String toString() {
        int nbItem = this.getNumberItems();
        String text;
        switch (nbItem) {
            case 0:
                text = "Votre panier est vide";
                break;
            case 1:
                text = "Votre panier contient 1 Article";
                break;
            default:
                text = "Votre panier contient " + String.valueOf(nbItem) + " Articles";
                break;
        }
        return text;
    }
}
